package com.itheima.management.controller;


import com.itheima.management.service.ManageVideoService;
import com.itheima.management.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("manage")
public class ManageVideoController {



    @Autowired
    private ManageVideoService manageVideoService;

    /**
     *                  视频记录翻页
     *
     * @param userId            用户id
     * @param page
     * @param pageSize
     * @param sortProp          排序字段
     * @param sortOrder         ASC升序  DESC降序
     * @return
     */
    @GetMapping("videos")
    public ResponseEntity<PageResult> queryVideo(@RequestParam("uid") Long userId,
                                                 @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                 @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                                 @RequestParam("sortProp") String sortProp,
                                                 @RequestParam("sortOrder") String sortOrder){

        try {
            if (page <= 0) {
                page = 1;
            }
            PageResult pageResult =this.manageVideoService.queryVideoList(userId,page,pageSize,sortProp,sortOrder);

            if (pageResult != null){

                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
